package com.qiantu.phone.ui.activity;

import android.content.Intent;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.qiantu.api.db.LLDeviceDBManager;
import com.qiantu.api.db.LLRoomDBManager;
import com.qiantu.api.entity.DeviceBean;
import com.qiantu.phone.R;
import com.qiantu.phone.app.AppActivity;
import com.qiantu.phone.ui.adapter.DataSourceDeviceAdapter;

import java.util.List;

/**
 * time   : 2021/12/22
 */
public class DataSourceDeviceActivity extends AppActivity {

    private RecyclerView recyclerView;
    public DataSourceDeviceAdapter mDataSourceDeviceAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_data_source_device;
    }

    @Override
    protected void initView() {
        recyclerView = findViewById(R.id.recycler_view);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        mDataSourceDeviceAdapter = new DataSourceDeviceAdapter(getContext());
        String deviceSerialNo = getString("device_serial_no");
        String roomSerialNo = getString("room_serial_no");
        int environmentType = getInt("environment_type");
//        List<DeviceBean> data = LLDeviceDBManager.getInstance(getContext()).getEnvironmentDevices(environmentType);
        List<DeviceBean> data = LLDeviceDBManager.getInstance(getContext()).getRoomEnvironmentDevices(roomSerialNo, environmentType);
        mDataSourceDeviceAdapter.setData(data);
        mDataSourceDeviceAdapter.checkSelected(deviceSerialNo);
        recyclerView.setAdapter(mDataSourceDeviceAdapter);
    }

    @Override
    public void onRightClick(View view) {
        DeviceBean device = mDataSourceDeviceAdapter.getSelected();
        Intent data = new Intent();
        data.putExtra("floor_room_name", LLRoomDBManager.getInstance(this).getFloorRoomName(device.getRoomSerialNo()));
        data.putExtra("room_serial_no", device.getRoomSerialNo());
        data.putExtra("device_name", device.getName());
        data.putExtra("device_serial_no", device.getDeviceSerialNo());
        setResult(RESULT_OK, data);
        finish();
    }

    @Override
    protected void initData() {

    }
}